<template>
  <Main :type="'form'">
    <Title :title="'文章页设置'" />
    <el-row>
      <el-col :span="24">
        <el-form ref="form" :model="form" :rules="form" label-width="130px">
          <el-form-item
            label="页面标题"
            prop="title"
            :rules="{
              required: true,
              message: '请输入页面标题',
              trigger: 'blur'
            }"
          >
            <el-input
              v-model="form.title"
              placeholder="请输入页面标题"
              :maxlength="5"
              style="line-height: 20px; width:50%;"
              show-word-limit
            ></el-input>
          </el-form-item>
          <el-form-item label="浏览权限" :rules="{ required: true }">
            <el-radio-group v-model="form.auth">
              <el-radio :label="1">全部用户</el-radio>
              <el-radio :label="2">仅会员</el-radio>
              <el-radio :label="3">普通会员</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <Footer>
      <el-button type="primary" @click="submit">保存</el-button>
    </Footer>
  </Main>
</template>
<script>
import { SETARTICLECONFIG } from "../service";

export default {
  data() {
    return {
      form: {
        title: "",
        auth: 1
      }
    };
  },
  created() {
    this.getMsg();
  },

  methods: {
    async submit() {
      await this.$refs["form"].validate(valid => {
        if (valid) {
          let prams = {
            title: this.form.title,
            auth: this.form.auth,
            flag: "save"
          };
          SETARTICLECONFIG(prams).then(({ code, msg }) => {
            this.$message({
              message: msg,
              type: code === 200 ? "success" : "error"
            });
          });
        } else {
          return false;
        }
      });
    },
    async getMsg() {
      await SETARTICLECONFIG().then(({ code, data }) => {
        if (code === 200) {
          this.form.title = data.title;
          this.form.auth = data.auth;
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.imgs {
  width: 40px;
  height: 40px;
  float: left;
  border: 1px solid #dcdfe6;
  margin-right: 10px;
  border-radius: 5px;
  overflow: hidden;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>
